package main

import (
	"bytes"
	"fmt"
	"io"
	"lnzw/engine/log"
	"net/http"

	"go.uber.org/zap"
)

const (
	api_key_name  = ""
	api_key_token = "sk-7de9fde7654e4d6a99e7a7f491208b02"
	ds_url        = "https://api.deepseek.com/chat/completions"
)

func main() {
	log.Setup()
	json := `{"model": "deepseek-chat",  
			  "messages": [
          			{"role": "system", "content": "You are a helpful assistant."},
          			{"role": "user", "content": "Hello!"}],
			  "stream": false
			}`
	req, err := http.NewRequest("POST", ds_url, bytes.NewBuffer([]byte(json)))
	if err != nil {
		log.Error("new request error", zap.Error(err))
		return
	}
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Authorization", "Bearer "+api_key_token)
	client := &http.Client{}
	rsp, err := client.Do(req)
	if err != nil {
		log.Error("new request error", zap.Error(err))
		return
	}
	defer rsp.Body.Close()
	// 检查响应状态码
	if rsp.StatusCode != http.StatusOK {
		log.Error(fmt.Sprintf("Error: unexpected status code: %d", rsp.StatusCode))
		return
	}
	// 读取响应体
	body, err := io.ReadAll(rsp.Body)
	if err != nil {
		fmt.Println("Error reading response body:", err)
		return
	}
	fmt.Println(string(body))
}
